import instacne from "../request";
import type { Ref } from "vue";


/**
 * 登录返回数据
 */
interface IAdminLoginParams {
  password: string;
  username: string;
}
interface IAdminLoginRes {
  tokenHead: string;
  token: string;
}


const adminLogin = (data: IAdminLoginParams): Promise<IAdminListItem> => {
  // instacne.post("/auth/login", data); 是一个 Promise 类型
  return instacne.post("/admin/login", data);
};


//获取index首页 图标数据
const getIndexDataApi = (): Promise<IIndexStat> => {
  return instacne.get(`http://kumanxuan1.f3322.net:8360/admin/stat`)
}




/**
 * 获取当前登录用户信息
 */
interface IAdminInfoRes {
  menus: IMneuItem[];
  icon: string;
  username: string;
  roles: string[];
}
const getAdminInfo = (): Promise<IAdminInfoRes> => {
  return instacne.get("/admin/info");
};

/**
 * /admin/list 根据用户名或者姓名获取用户列表
 */
interface IAdminListParams {
  keyword?: string | Ref<string>;
  pageNum?: number | Ref<number>;
  pageSize?: number | Ref<number>;
  id?: number | Ref<number>;
}

interface IAdminListItem {
  createTime: string;
  email: string;
  icon: string;
  id: number;
  loginTime: string;
  nickName: string;
  note: string;
  password: string;
  status: number;
  username: string;
}

interface IAdminListRes {
  list: IAdminListItem[];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}

interface IAdminOrder {
  code: 0,
  data: {
    commentOvertime: string,
    confirmOvertime: string,
    finishOvertime: string,
    flashOrderOvertime: string,
    id: number,
    normalOrderOvertime: string
  },
  message: string
}


// 退货原因
// interface returnReasonItem {
//   createTime: string,
//   id: number,
//   name: string,
//   sort: number,
//   status: number
// }
// interface returnOder {
//   code: 0,
//   data: returnReasonItem,
//   message: string
// }

const getAdminList = (data?: IAdminListParams): Promise<IAdminListRes> => {
  return instacne.get("/admin/list", {
    params: data,
  });
};

/**
 * 新增用户
 * admin/register
 */
const adminRegister = (data: IAdminListItem): Promise<IAdminListItem> => {
  return instacne.post("/admin/register", data);
};

/**
 * /admin/update/{id}
 *  修改指定用户信息
 */
const adminUpdate = (data: IAdminListItem) => {
  return instacne.post(`/admin/update/${data.id}`, data)

}

// 获取订单设置信息
// const orderSetting = (data: any): Promise<any> => {
//   return instacne.get(`/orderSetting/${data.id}`, data)
// }


// 获取退货申请处理
// const returnApply = (): Promise<any> => {
//   return instacne.get(`/returnApply/list`)
// }

// 获取退货原因详情数据
// const returnApplyDetail = (data: any): Promise<any> => {
//   return instacne.get(`/returnApply/${data.id}`, data)
// }

// 分页查询全部退货原因
// const returnReason = (): Promise<any> => {
//   return instacne.get(`/returnReason/list`)
// }



/* 
     resource  /resource/list?pageNum=1&pageSize=10
*/
const getAdmineresource = (data?: IAdminListParams): Promise<IAdminListRes> => {
  return instacne.get("/resource/list", {
    params: data,
  });
};
/* 
    /menu/list/  菜单列表  
*/
const getAdminmenu = (data?: IAdminListParams): Promise<IAdminListRes> => {
  console.log("data", data);


  return instacne.get(`/menu/list/` + (data?.id ? data?.id : 0), {
    params: {
      pageNum: data?.pageNum,
      pageSize: data?.pageSize
    }
  });
};

interface datamenu {
  createTime: string
  hidden: number
  icon: string
  id: number
  level: number
  name: string
  parentId: number
  sort: number
  title: string
}
interface adminaddmenu {
  data: datamenu[]
}

/* 
    /productCategory/list/0  商品分类
*/
interface IgoodsList {
  pageNum?: number | Ref<number>
  pageSize?: number | Ref<number>
  id?: number | Ref<number>
}

const getAdminproductCategory = (data?: IgoodsList): Promise<IAdminListRes> => {
  // console.log(Number(data?.id));


  return instacne.get("/productCategory/list/" + (data?.id ? data?.id : 0), {
    params: {
      pageNum: data?.pageNum,
      pageSize: data?.pageSize
    }
  });
};

interface adminCreateItem {
  hidden?: number,
  icon?: string,
  name?: string,
  parentId?: number,
  sort?: number | string,
  title?: string,


  id?: number,
  region?: string,
  description?: string,
  keywords?: string,
  navStatus?: number,
  productAttributeIdList?: number[],
  productUnit?: string,
  showStatus?: number
}

const adminCreate = (data: adminCreateItem): Promise<adminCreateItem> => {
  return instacne.post("/menu/create", data);
};

const adminCategoryCreate = (data: adminCreateItem): Promise<adminCreateItem> => {
  return instacne.post("/productCategory/create", data);
}
interface IGoodslistData {
  brandId?: number | Ref<number>
  keyword?: string | Ref<string>
  pageNum?: number | Ref<number>
  pageSize?: number | Ref<number>
  productCategoryId?: number | Ref<number>
  productSn?: string | Ref<string>
  publishStatus?: number | Ref<number>
  verifyStatus?: number | Ref<number>
}

interface IGoosOlldata {
  pageNum: number,
  pageSize: number,
  total: number,
  totalPage: number,
  list: any[]
}
const getAdminID = (id: number): Promise<adminaddmenu> => {
  return instacne.get(`/menu/${id}`);
};


/**
 * /product/list  查询商品
 */
const getGoodsList = (data: IGoodslistData): Promise<IGoosOlldata> => {
  return instacne.get('/product/list', { params: data })
}


/**
 * /product/update/publishStatus 批量上下架
 */
interface UPpublish {
  ids: number | number[]
  publishStatus: number
}
const uppublishStatus = (data: UPpublish) => {
  return instacne.post(`/product/update/publishStatus?ids=${data.ids}&publishStatus=${data.publishStatus}`)
}
/**
 * /product/update/newStatus 批量设为新品
 */
interface UPnewStatus {
  ids: number | number[]
  newStatus: number
}
const upnewStatus = (data: UPnewStatus) => {
  return instacne.post(`/product/update/newStatus?ids=${data.ids}&newStatus=${data.newStatus}`)
}

/**
 * /product/update/recommendStatus  批量推荐商品
 */
interface IUprecommendStatus {
  ids: number | number[]
  recommendStatus: number
}
const uprecommendStatus = (data: IUprecommendStatus) => {
  return instacne.post(`/product/update/recommendStatus?ids=${data.ids}&recommendStatus=${data.recommendStatus}`)
}

/**
 * /product/update/deleteStatus 批量修改删除状态
 */
interface IDeletes {
  ids: number | number[]
  deleteStatus: number
}
const deleteStatus = (data: IDeletes) => {
  return instacne.post(`/product/update/deleteStatus?ids=${data.ids}&deleteStatus=${data.deleteStatus}`)
}

/**
 * /flash/list 根据优惠券名称和类型分页获取优惠券列表
 */

interface ICouponData {
  name?: string | Ref<string>
  pageNum?: number | Ref<number>
  pageSize?: number | Ref<number>
  type?: number | Ref<number>
}
interface ICouponPomis {
  list: any[]
  pageNum: number,
  pageSize: number,
  total: number,
  totalPage: number

}

const getcouponList = (data: ICouponData): Promise<ICouponPomis> => {
  return instacne.get('/flash/list', { params: data })
}
/**
 * /coupon/list  根据优惠券名称和类型分页获取优惠券列表
 */

const getAdminattrInfo = (id: any) => {
  return instacne.get(`/productCategory/${id}`);
};



const getAdminproductCategoryo = (data: adminCreateItem): Promise<adminCreateItem> => {
  return instacne.post(`/productCategory/update/${data.id}`, data);
};

const adminproductCategorydelete = (id: number) => {
  return instacne.post(`/productCategory/delete/${id}`);
};

interface datahidden {
  id?: number,
  hidden?: number
}
const adminupdateHidden = (data?: datahidden): Promise<datahidden> => {
  return instacne.post(`/menu/updateHidden/${data?.id}?hidden=${data?.hidden}`);
};

const getAdminwithAttr = () => {
  return instacne.get("/productAttribute/category/list/withAttr");
};

interface ICouponListdata {

  name?: string | Ref<string>
  pageNum?: number | Ref<number>
  pageSize?: number | Ref<number>
  type?: number | Ref<number>
}
interface ICouponres {
  list: any
  pageNum: number,
  pageSize: number,
  total: number,
  totalPage: number
}
const getCouponListres = (data: ICouponListdata): Promise<ICouponres> => {
  return instacne.get('/coupon/list', { params: data })
}


/**
 * /coupon/delete/{id} 删除优惠券
 */
const deleteCoupon = (id: number | Ref<number>) => {
  return instacne.post(`/coupon/delete/${id}`)
}
/**
 * /home/brand/list 分页查询推荐品牌
 */
interface IHomeBranddata {
  brandName?: string | Ref<string>
  pageNum?: number | Ref<number>
  pageSize?: number | Ref<number>
  recommendStatus?: number | Ref<number>
}
interface IHomeBrandRes {
  list: any[]
  pageNum: number,
  pageSize: number,
  total: number,
  totalPage: number
}
const getHomeList = (data: IHomeBranddata): Promise<IHomeBrandRes> => {
  return instacne.get('/home/brand/list', { params: data })
}
/**
 * /flash/update/status/{id} 修改上下线状态
 */
interface IUpdateData {
  status?: number | Ref<number>
  id?: number | Ref<number>

}
const updateStatus = (data: IUpdateData) => {
  return instacne.post(`/flash/update/status/${data.id}?status=${data.status}`, data)
}
/**
 * /flash/update/{id} 编辑活动
 */
interface IFlashUpdate {
  createTime?: string | Ref<string>,
  endDate?: string | Ref<string>,
  id?: number | Ref<number>,
  startDate?: string | Ref<string>,
  status?: number | Ref<number>,
  // title?: string | Ref<string>
  title?: string | Ref<string>,
  name?: string | Ref<string>
}
const flashUpdate = (data: IFlashUpdate) => {
  return instacne.post(`/flash/update/${data.id}`, data)
}
/**
 * /flash/delete/{id} 删除活动
 */
const flashDelete = (id: number) => {
  return instacne.post(`/flash/delete/${id}`)
}
/**
 * /flash/create 添加活动
 */
const CFlashCreate = (data: IFlashUpdate) => {
  return instacne.post(`/flash/create`, data)
}
/**
 * /flashSession/list   获取全部场次
 */
interface ssssssssss {
  createTime: string,
  endTime: string,
  id: number,
  name: string,
  startTime: string,
  status: number
}
interface IFlashSessList {
  data: ssssssssss[]
  message: string
}
const getFlashSessList = (): Promise<IFlashSessList> => {
  return instacne.get(`/flashSession/list  `)
}

/**
 * /flashSession/create 添加场次
 */

interface ICreateSession {
  createTime?: string | Ref<string>,
  endTime?: string | Ref<string>,
  id?: number | Ref<number>,
  name?: string | Ref<string>,
  startTime?: string | Ref<string>,
  status?: number | Ref<number>
}
const CreateSession = (data: ICreateSession) => {
  return instacne.post(`/flashSession/create`, data)
}

/**
 * /flashSession/delete/{id}  删除场次
 */

const DeleteSession = (id: number | Ref<number>) => {
  return instacne.post(`/flashSession/delete/${id}`)
}
/**
 * /flashSession/update/{id}  修改场次
 */

const UpdateSession = (data: ICreateSession) => {
  return instacne.post(`/flashSession/update/${data.id}`, data)
}

/**
 * /flashSession/selectList  获取全部可选场次及其数量
 */

const selectListSession = (flashPromotionId?: number | Ref<number>) => {
  return instacne.get(`/flashSession/selectList?flashPromotionId=${flashPromotionId}`)
}
/**
 * /flashProductRelation/list 分页查询不同场次关联及商品信息
 */
interface IProductData {
  pageNum?: number | Ref<number>,
  pageSize?: number | Ref<number>,
  flashPromotionSessionId?: number | Ref<number>,
  flashPromotionId?: number | Ref<number>
}
interface IProductRes {
  list: any[]
  pageNum: number,
  pageSize: number,
  total: number,
  totalPage: number
}
const ProductRelationList = (data: IProductData): Promise<IProductRes> => {
  return instacne.get(`/flashProductRelation/list`, { params: data })
}

/**
 * /product/list?pageNum=1&pageSize=5  /product/list  查询商品
 */
interface IProductListData {
  keyword?: string | Ref<string>
  pageNum?: number | Ref<number>
  pageSize?: number | Ref<number>
  total?: number | Ref<number>
  totalPage?: number | Ref<number>
  productCategoryId?: number | Ref<number>
  brandId?: number | Ref<number>
  publishStatus?: number | Ref<number>
  verifyStatus?: number | Ref<number>
  productSn?: string | Ref<string>
}

const GProductList = (data: IProductListData): Promise<IProductRes> => {
  return instacne.get(`/product/list`, { params: data })
}

// 退货原因
interface returnReasonItem {
  createTime: string,
  id: number,
  name: string,
  sort: number,
  status: number
}
interface returnOder {
  code: 0,
  data: returnReasonItem,
  message: string
}
interface returnReasonlist {
  createTime: string;
  id: number;
  name: string;
  sort: number;
  status: number;
  ischeck?: boolean;
}
// 获取订单设置信息
const orderSetting = (data: any): Promise<any> => {
  return instacne.get(`/orderSetting/${data.id}`, data)
}

// 获取退货申请处理
const returnApply = (data: any): Promise<any> => {
  return instacne.get(`/returnApply/list/`, { params: data })
}

// 获取退货原因详情数据
const returnApplyDetail = (data: any): Promise<any> => {
  return instacne.get(`/returnApply/${data.id}`, data)
}

// 获取订单详情
const OrderDetailAPI = (params: number): Promise<any> => {
  return instacne.get("order/" + params);
};

// 分页查询全部退货原因
const returnReason = (data?: any): Promise<any> => {
  return instacne.get(`/returnReason/list`, { params: data })
}

// 退货原因设置删除
const DeleteReason = (data: returnReasonlist): Promise<any> => {
  return instacne.post(`returnReason/delete?ids=${data.id}`)
}

// /returnReason/create
const getreturnReasonlistadd = (
  data: returnReasonlist
): Promise<returnReasonlist> => {
  return instacne.post("/returnReason/create", data);
};
// /returnReason/update/{id}
const getreturnReasonlistUpdate = (data: returnReasonlist) => {
  return instacne.post(`/returnReason/update/${data.id}`, data);
};
// /returnReason/update/status
const getreturnReasonlistUpdatestatus = (data: returnReasonlist) => {
  return instacne.post(
    `/returnReason/update/status?status=${data.status}&ids=${data.id}`
  );
};
export {
  getAdmineresource,
  getAdminmenu,
  getAdminproductCategory,
  getGoodsList,
  uppublishStatus,
  upnewStatus,
  uprecommendStatus,
  deleteStatus,
  getcouponList,
  getCouponListres,
  deleteCoupon,
  getHomeList,
  updateStatus,
  flashUpdate,
  // flashDelete
  flashDelete,
  CFlashCreate,
  getFlashSessList,
  CreateSession,
  DeleteSession,
  UpdateSession,
  selectListSession,
  ProductRelationList,
  GProductList,
  OrderDetailAPI,
  getreturnReasonlistUpdatestatus,
  getreturnReasonlistUpdate,
  getreturnReasonlistadd,
  DeleteReason,
  orderSetting,
  returnApply,
  returnApplyDetail,
  returnReason
};
export type { IGoosOlldata };

export function getAdminRole(getAdminRole: any, arg1: { keyword: Ref<string>; }): { tableData: any; getTableData: any; pagination: any; handleSizeChange: any; handleCurrentChange: any; } {
  throw new Error('Function not implemented.');
}


export function rolesRegister(row: IAdminListItem) {
  throw new Error('Function not implemented.');
}

export { adminLogin, getAdminInfo, getAdminList, adminRegister, adminUpdate, adminCreate, getAdminattrInfo, getAdminID, adminproductCategorydelete, adminCategoryCreate, adminupdateHidden, getAdminproductCategoryo, getAdminwithAttr };
export type { IAdminLoginParams, IAdminLoginRes, IAdminListItem, adminCreateItem };
